<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/js-cookie/3.0.1/js.cookie.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.js"></script>
</head>
<body>
  <h1>管理界面: 只有登陆了才能访问</h1>
  <h3>cookie数据: <span id="cookie"></span></h3>
  <h3>登陆用户: <span id="username"></span></h3>

  <script>
    // 浏览器端读取cookie数据
    // 得到是所有cookie组成串   a=1; b=2
    // 原生cookie比较麻烦  => 一般会使用cookie操作的工具库: js-cookie
    const cookie = document.cookie  
    console.log(cookie)
    document.getElementById('cookie').innerHTML = cookie

    // 得到cookie中userId
    const userId = Cookies.get('userId')
    // 发ajax请求获取用户信息
    axios('/info').then(
      response => {
        const user = response.data
        document.getElementById('username').innerHTML = user.username
      }
    )

  </script>
</body>
</html>